package com.daon.controller;

import com.daon.pojo.SysNode;
import com.daon.service.ISysNodeService;
import com.daon.service.ITreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author 1daon
 * @EMAIL 532418116@qq.com
 * @Version 创建时间：2019/3/21 17:08 PM
 * @Modified By
 */
@Controller
@RequestMapping("/sys")
public class SystemController {

    @Autowired
    private ISysNodeService iSysNodeService;
    @Autowired
    private ITreeService iTreeService;

    @RequestMapping
    public void index(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.sendRedirect("/sys/index.page");
    }

    @RequestMapping("index.page")
    public ModelAndView index(){
        List<SysNode> sysNodeList = iSysNodeService.getNodeListByCurrentUserId();
        List<Object> sysNodeTree = iTreeService.nodeMenu2TreeArray(sysNodeList);
        ModelAndView mav=new ModelAndView("/backend/system/index");
        mav.getModel().put("sysNodeTree", sysNodeTree);
        return mav;
    }

    @RequestMapping("default.page")
    public ModelAndView defaults(){
        return new ModelAndView("/backend/system/default");
    }

    @RequestMapping("icon.page")
    public ModelAndView icon(){
        return new ModelAndView("/backend/system/icon");
    }
}
